package com.atguigu.tingshu.handler;

import com.atguigu.tingshu.model.CDCEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * @author: atguigu
 * @create: 2024-04-19 15:19
 */
@Slf4j
@Component
@CanalTable("user_info")
public class UserInfoCdcHandler implements EntryHandler<CDCEntity> {

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 监听到数据表album_info记录修改，将Redis中数据进行删除
     *
     * @param before 修改前记录
     * @param after  修改后记录
     */
    @Override
    public void update(CDCEntity before, CDCEntity after) {
        log.info("[CDC]监听到数据更新,删除缓存：{}", after);
        String key = "user:info:" + after.getId();
        redisTemplate.delete(key);
    }


}
